home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group93b.txt / 000093_icon-group-sender _Sun May 16 17:30:41 1993.msg < prev    next >
Internet Message Format  |  1993-06-16  |  2KB

  1. Received: from owl.CS.Arizona.EDU by cheltenham.cs.arizona.edu; Mon, 17 May 1993 07:43:30 MST
  2. Received: by owl.cs.arizona.edu; Mon, 17 May 1993 07:43:29 MST
  3. Date: 16 May 93 17:30:41 GMT
  4. From: sdd.hp.com!portal!cup.portal.com!Eric-Amick@hplabs.hpl.hp.com  (Richard E Amick)
  5. Organization: The Portal System (TM)
  6. Subject: Re: string stripping
  7. Message-Id: <81483@cup.portal.com>
  8. References: <12646.9305141703@desktop.desktop.co.uk>
  9. Sender: icon-group-request@cs.arizona.edu
  10. To: icon-group@cs.arizona.edu
  11. Status: R
  12. Errors-To: icon-group-errors@cs.arizona.edu
  13.  
  14. >procedure main()
  15. >
  16. >full := "abc-def.ghi"
  17. >bare := ""
  18. >badchars := '-.'
  19. >
  20. >full ? {
  21. >    while bare ||:= tab(many(~badchars)) do
  22. >        tab(many(badchars))
  23. >}
  24. >write(bare)
  25. >
  26. >end
  27. >
  28. >You may notice that despite my suggestion of using "upto()"
  29. >I actually used tab(many(~badchars)).  This allows you to include
  30. >any trailing good characters as a part of the loop processing
  31. >rather than having to program in possible special cases.
  32. >
  33. >This group being what it is you may well get several other good
  34. >(possibly even better :-) ideas on how to go about this.
  35.  
  36. Your solution won't work if the string starts off with bad characters.
  37. On the other hand, making the scanning loop read as follows works:
  38.  
  39.     while tab(upto(~badchars)) do
  40.         bare ||:= tab(many(~badchars))
  41.  
  42. The only likely objection might be that creating what is almost always a
  43. large cset of good characters is inefficient, but I don't think that's a
  44. horrible thing in this case (and Icon is not renowned for blazing speed
  45. anyway :-).  Maybe you should have taken your own advice about upto(),
  46. eh? ;-)
  47. >
  48. >regards
  49. > Steve
  50.